<script>
$(document).ready(function() {
	callauto("prabhas", "<?= site_url('prabhas/get_product')?>", "hid_prabhas");
});

function callauto(id, url, hid) {
	alert(id)
	alert(url)
	alerts(hid)
	if ($("#"+id).val()==""){
		$("#"+id).addClass("ac_dropdown");
	} else {
		$("#"+id).addClass("ac_remove");
	}
	$(".ac_remove").live("click", function(){ 
		this.value = "";
		$(this).removeClass('ac_remove');
		$(this).addClass('ac_dropdown');
	});
	$("#"+id).live("keyup", function(){
		if ($("#"+id).val()==""){
			$(this).removeClass('ac_remove');
			$(this).addClass('ac_dropdown');
		} else {
			$(this).addClass('ac_remove');
			$(this).removeClass('ac_dropdown');
		}
	});
	$(".ac_dropdown").live("click", function(){
		$("#"+id).autocomplete( "search", "a" );
	});
	$("#"+id).autocomplete({
		source : function(request, response) {
			var name = $("#"+id).val();
			alert(name)
			$.ajax({
				url: url,
				dataType: "json", 
				data : {
					filter : name
				},           
				success : function(data) {
					alert(data)
					response(jQuery.map(data,function(item) {
						return {
							value : item.name,
							key : item.name
						};
					}));
				}
			}); 
		},
		select : function(event, ui) {
			$("#"+hid).val(ui.item.key) ;
			$(this).addClass('ac_remove');
			$(this).removeClass('ac_dropdown');
		}
	});
}
</script>
<table width="100%" class="table table-bordered" >
<tr>
<td>Username</td><td><input type="text" name="prabhas" id="prabhas"></td>
<td><input type="text" name="hid_prabhas" id="hid_prabhas"></td>
</tr>
</table>





